package com.ruoyi.blog.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.blog.domain.BlogType;
import com.ruoyi.blog.service.IBlogTypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 博客分类Controller
 * 
 * @author ruoyi
 * @date 2021-05-05
 */
@RestController
@RequestMapping("/blog/type")
public class BlogTypeController extends BaseController
{
    @Autowired
    private IBlogTypeService blogTypeService;

    /**
     * 查询博客分类列表
     */
    @PreAuthorize("@ss.hasPermi('blog:type:list')")
    @GetMapping("/list")
    public AjaxResult list(BlogType blogType)
    {
        List<BlogType> list = blogTypeService.selectBlogTypeList(blogType);
        return AjaxResult.success(list);
    }

    /**
     * 导出博客分类列表
     */
    @PreAuthorize("@ss.hasPermi('blog:type:export')")
    @Log(title = "博客分类", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BlogType blogType)
    {
        List<BlogType> list = blogTypeService.selectBlogTypeList(blogType);
        ExcelUtil<BlogType> util = new ExcelUtil<BlogType>(BlogType.class);
        return util.exportExcel(list, "博客分类数据");
    }

    /**
     * 获取博客分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('blog:type:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(blogTypeService.selectBlogTypeById(id));
    }

    /**
     * 新增博客分类
     */
    @PreAuthorize("@ss.hasPermi('blog:type:add')")
    @Log(title = "博客分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BlogType blogType)
    {
        return toAjax(blogTypeService.insertBlogType(blogType));
    }

    /**
     * 修改博客分类
     */
    @PreAuthorize("@ss.hasPermi('blog:type:edit')")
    @Log(title = "博客分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BlogType blogType)
    {
        return toAjax(blogTypeService.updateBlogType(blogType));
    }

    /**
     * 删除博客分类
     */
    @PreAuthorize("@ss.hasPermi('blog:type:remove')")
    @Log(title = "博客分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(blogTypeService.deleteBlogTypeByIds(ids));
    }
}
